# @Author   : 懒羊羊
# @File     : loginpage.py
# @Time     : 2024/12/11 19:04
import time

from appium.webdriver.common.appiumby import AppiumBy
from pages.basepage import BasePage
from pages.firstpage import FirstPage


class Login(BasePage):
    input_phone = (AppiumBy.ID, 'com.kkpodcast:id/input_phone_et')
    input_pwd = (AppiumBy.ID, 'com.kkpodcast:id/input_password_et')
    tyxy = (AppiumBy.CLASS_NAME, 'android.widget.CheckBox')
    input_dl = (AppiumBy.XPATH, '//*[@resource-id="com.kkpodcast:id/login_tv"]')
    my = (AppiumBy.ID, 'com.kkpodcast:id/mine_rb')
    error_message1 = (AppiumBy.XPATH, '//*[@text="请输入密码"]')
    error_message2 = (AppiumBy.XPATH, '//*[@text="密码错误"]')
    user_name = (AppiumBy.ID, 'com.kkpodcast:id/user_name_tv')

    def login(self, username='19286685595', pwd='123456789'):
        # 输入手机号
        if username == None:
            username = ''
        if pwd == None:
            pwd = ''
        self.set_Ele_Value(self.input_phone, username)
        # 输入密码
        self.set_Ele_Value(self.input_pwd, pwd)
        # 勾选同意协议
        is_checked = self.getElement(self.tyxy).get_attribute("checked") == "true"
        if not is_checked:
            self.getElement(self.tyxy).click()

        # 点击登录
        self.getElement(self.input_dl).click()

    def go_to_firstpage(self):
        self.login()
        return FirstPage(self.d)

    def login_ok(self):
        return self.get_Ele_Value(self.my)

    def login_error1(self):
        return self.get_Ele_Value(self.error_message1)

    def login_error2(self):
        return self.get_Ele_Value(self.input_dl)


if __name__ == '__main__':
    l = Login()
    l.login()
    l.login_ok()
